<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
<!--[if lt IE 9]>
<script type="text/javascript" src="lib/html5shiv.js"></script>
<script type="text/javascript" src="lib/respond.min.js"></script>
<![endif]-->
<link rel="stylesheet" type="text/css" href="static/h-ui/css/H-ui.min.css" />
<link rel="stylesheet" type="text/css" href="static/h-ui.admin/css/H-ui.admin.css" />
<link rel="stylesheet" type="text/css" href="lib/Hui-iconfont/1.0.8/iconfont.css" />
<link rel="stylesheet" type="text/css" href="static/h-ui.admin/skin/default/skin.css" id="skin" />
<link rel="stylesheet" type="text/css" href="static/h-ui.admin/css/style.css" />
<!--[if IE 6]>
<script type="text/javascript" src="lib/DD_belatedPNG_0.0.8a-min.js" ></script>
<script>DD_belatedPNG.fix('*');</script>
<![endif]-->
<title>线路管理</title>
</head>
<body>
<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页
	<span class="c-gray en">&gt;</span>
	基础信息管理
	<span class="c-gray en">&gt;</span>
	线路管理
	<a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a>
</nav>
<div class="page-container" id="app">
	<div class="text-c">
		<span class="select-box inline" v-if="isAdmin">
			<select class="select" id="companyid" name="companyid"></select>
		</span>
		<input type="text" name="" id="query" placeholder="线路名称" style="width:250px" class="input-text" v-model="msg">
		<button name="" id="" class="btn btn-success" type="submit" v-on:click="query()"><i class="Hui-iconfont">&#xe665;</i> 搜索</button>
		<button class="btn btn-success" type="button" v-on:click="synchronizeLines()"><i class="Hui-iconfont">&#xe642;</i> 同步线路</button>
	</div>
	<div class="mt-20">
		<table id="list" class="table table-border table-bordered table-hover table-bg table-sort">
		</table>
	</div>
</div>
<!--_footer 作为公共模版分离出去-->
<script type="text/javascript" src="lib/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript" src="lib/layer/2.4/layer.js"></script>
<script type="text/javascript" src="static/h-ui/js/H-ui.min.js"></script>
<script type="text/javascript" src="static/h-ui.admin/js/H-ui.admin.js"></script> <!--/_footer 作为公共模版分离出去-->

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="lib/My97DatePicker/4.8/WdatePicker.js"></script>
<script type="text/javascript" src="lib/datatables/1.10.0/jquery.dataTables.js"></script>
<script type="text/javascript" src="lib/laypage/1.2/laypage.js"></script>
<script type="text/javascript" src="js/jquery.base64.js"></script>
<script type="text/javascript" src="js/vue.js" charset="utf-8"></script>
<script type="text/javascript">
/*系统-线路-添加*/
function system_category_add(title,url,w,h){
	layer_show(title,url,w,h);
}
/*系统-线路-编辑*/
function system_category_edit(title,url,id,w,h){
	layer_show(title,url,w,h);
}
/*系统-线路-删除*/
function system_category_del(obj,id){
	layer.confirm('确认要删除吗？',function(index){
		$.ajax({
			type: 'POST',
			url: '',
			beforeSend: function (request) {
				request.setRequestHeader("Authorization", "Bearer " + getToken());
			},
			dataType: 'json',
			success: function(data){
				$(obj).parents("tr").remove();
				layer.msg('已删除!',{icon:1,time:1000});
			},
			error:function(data) {
				console.log(data.msg);
			},
		});
	});
}
</script>

<script type="text/javascript">
	$(function(){
		$.ajax({
			url: ipAddress + 'base/company/getList',
			// url: 'http://localhost:8080/base/company/getList',
			data: {
				order: "ordercode"
			},
			beforeSend: function (request) {
				request.setRequestHeader("Authorization", "Bearer " + getToken());
			},
			method:'GET',
			success:function (data,status,request) {
				$("#companyid").append("<option value>请选择分公司</option>");
				for(var i = 0; i < data.length; i ++){
					$("#companyid").append("<option value='" + data[i].companyid + "'>" + data[i].companyname + "</option>");
				}
			},
			error:function (request, msg, obj) {
				var respTxtObj = JSON.parse(request.responseText);
				console.log(respTxtObj);
				console.log(respTxtObj.error);
				console.log(respTxtObj.error_description);
			}
		});
	});
	
	
	var vm = new Vue({
		el : "#app",
		data : {
			msg : "",
			isAdmin : true,
			userInfo : getUserInfo()
		},
		//在实例初始化之后，数据观测 (data observer) 和 event/watcher 事件配置之前被调用。
		beforeCreate:function(){
			console.log('beforeCreate');
		},
		/* 在实例创建完成后被立即调用。
		在这一步，实例已完成以下的配置：数据观测 (data observer)，属性和方法的运算，watch/event 事件回调。
		然而，挂载阶段还没开始，$el 属性目前不可见。 */
		created	:function(){
			this.isAdmin = hasRole('ADMIN');
			console.log('created');
		},
		//在挂载开始之前被调用：相关的渲染函数首次被调用
		beforeMount : function(){
			console.log('beforeMount');
	
		},
		//el 被新创建的 vm.$el 替换, 挂在成功	
		mounted : function(){
			console.log('mounted');
		
		},
		//数据更新时调用
		beforeUpdate : function(){
			console.log('beforeUpdate');
				
		},
		//组件 DOM 已经更新, 组件更新完毕 
		updated : function(){
			console.log('updated');
				
		},
		methods: {
			query: function(){
				var companyid;
				if(hasRole('COMPANY')){
					companyid = vm.userInfo.company.companyid;
				} else {
					companyid = $('#companyid').val();
				}
				$.ajax({
					type: 'GET',
					url: ipAddress + 'base/line/getList',
					data: {
						linename: this.msg,
						// order: "ordercode asc",
						'team.company.companyid': companyid,
						like: "%linename%",
						order: "ordercode"
						// page: 0,
						// size: 10
					},
					beforeSend: function (request) {
						request.setRequestHeader("Authorization", "Bearer " + getToken());
					},
					dataType: 'json',
					success: function(data){
						table.fnClearTable();   //将数据清除
						if(data.length > 0){
							table.fnAddData(data,true);  //数据必须是json对象或json对象数组
						}
						console.log(data);
					},
					error:function(data) {
						console.log(data.msg);
					},
				});
			},
			synchronizeLines: function(){
				var companyid;
				if(hasRole('COMPANY')){
					companyid = vm.userInfo.company.companyid;
				} else {
					companyid = $('#companyid').val();
				}
				$.ajax({
					type: 'GET',
					url: ipAddress + 'base/line/synchronizeLines',
					data: {
						companyid: companyid
					},
					beforeSend: function (request) {
						request.setRequestHeader("Authorization", "Bearer " + getToken());
					},
					dataType: 'json',
					success: function(data){
						alert(data.msg);
						console.log(data);
					},
					error:function(data) {
						console.log(data.msg);
					},
				});
			}
		}
	});
	
	var table = $('#list').dataTable({
		"bProcessing" : true, //DataTables载入数据时，是否显示‘进度’提示  
		"bAutoWidth" : true, //是否自适应宽度  
		"lengthMenu":[10, 50, 100],
		"pageLength": 100,
		"aaSorting": [[ 1, "asc" ]],//默认第几个排序
		//"bStateSave": true,//状态保存
		"aoColumnDefs": [
			//{"bVisible": false, "aTargets": [ 3 ]} //控制列的隐藏显示
			{"orderable":false,"aTargets":[0,4]}// 制定列不参与排序
		],
		bDeferRender: true, 
		"aoColumns" : [{  
			"mDataProp" : this.settings,  
			"sTitle" : "<input type='checkbox'/>", 
			"sDefaultContent" : "<input type='checkbox' value=''/>" //此列默认值为""，以防数据中没有此值，DataTables加载数据的时候报错  
			// "sClass": "text-center"
			// "bVisible" : false //此列不显示  
		}, {  
			"mDataProp" : "ordercode",  
			"sTitle" : "排序",  
			"sDefaultContent" : "",  
			"sClass" : "center"  
		}, {  
			"mDataProp" : "lineid",  
			"sTitle" : "编号",  
			"sDefaultContent" : "",  
			"sClass" : "center"  
		}, {  
			"mDataProp" : "linename",  
			"sTitle" : "线路名称",  
			"sDefaultContent" : "",  
			"sClass" : "center"  
		}, {  
			"mDataProp" : "lineid",  
			"sTitle" : "操作",  
			"sDefaultContent" : "",  
			"sClass" : "center"  
		}],
		"sAjaxSource" : ipAddress + "base/line/getTableList",  
		//服务器端，数据回调处理  
		"fnServerData" : function(sSource, aDataSet, fnCallback) {  
			aDataSet = {"linename": vm.msg, "like": "%linename%", "order": "lineid"};
			if(hasRole('COMPANY')){
				aDataSet['team.company.companyid'] = vm.userInfo.company.companyid;
			} else {
				aDataSet['team.company.companyid'] = $('#companyid').val();
			}
			console.log(aDataSet);
			$.ajax({  
				"dataType" : 'json',  
				"type" : "GET",  
				"url" : sSource,  
				"data" : aDataSet,  
				"beforeSend": function (request) {
					request.setRequestHeader("Authorization", "Bearer " + getToken());
				},  
				"success" : fnCallback  
			});  
		}  
	});
</script>
</body>
</html>